﻿using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Cmp;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.ElevatorManage;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Domain.LogDomain;
using Zocono.WCS.Domain.PlcBytesObject;
using Zocono.WCS.Domain.PlcConnectPoolDomain;
using Zocono.WCS.Domain.ProcessModuleDomain;
using Zocono.WCS.Infrastructure.ApllicationDto.Enums;
using Zocono.WCS.Infrastructure.PlcCommon;
using Zocono.WCS.WMSApiDomain.WebApi;

namespace Zocono.WCS.Domain.EquipmentProcessDomain.PlanarGeneralMessage
{
    /// <summary>
    /// 到达十字路口-提升机前
    /// </summary>
    public class ArriveDDService : IPlanarGeneralPlcActionProcessService
    {
        private readonly IRedisHelper _IRedisHelper;
        private readonly IElevatorJudgeInfoRepository _IElevatorJudgeInfoRepository;
        private readonly IPlcConnectionPool _PlcConnectionPool;
        private readonly IWorkTaskInfoRepository _WorkTaskInfoRepository;
        private readonly IPlcWriteDbInfoRepository _PlcWriteDbInfoRepository;
        private readonly IPlcReadDbInfoRepository _PlcReadeDbInfoRepository;
        private readonly IPlcConnectionInfoRepository _PlcConnectionInfoRepository;
        private readonly IElevatorInfoRepository _IElevatorInfoRepository;
        private readonly IPlcConnectionStateInfoRepository _IPlcConnectionStateInfoRepository;
        private readonly IRunLogInfoService _IRunLogInfoService;
        private readonly IElevatorMasterInfoRepository _IElevatorMasterInfoRepository;

        private readonly ILogUtil _logUtil;
        public ArriveDDService(IRedisHelper iRedisHelper, IElevatorJudgeInfoRepository iElevatorJudgeInfoRepository
            , IElevatorMasterInfoRepository iElevatorMasterInfoRepository
            , IPlcConnectionPool plcConnectionPool
            , IWorkTaskInfoRepository workTaskInfoRepository
            , IPlcWriteDbInfoRepository plcWriteDbInfoRepository
            , IPlcConnectionInfoRepository plcConnectionInfoRepository
            , IElevatorInfoRepository elevatorInfoRepository
            , IPlcConnectionStateInfoRepository plcConnectionStateInfoRepository
            , IPlcReadDbInfoRepository plcReadDbInfoRepository
            , IRunLogInfoService iRunLogInfoService
            , ILogUtil logUtil)
        {
            _IRedisHelper = iRedisHelper;
            _IElevatorJudgeInfoRepository = iElevatorJudgeInfoRepository;
            _PlcConnectionPool = plcConnectionPool;
            _WorkTaskInfoRepository = workTaskInfoRepository;
            _PlcWriteDbInfoRepository = plcWriteDbInfoRepository;
            _PlcConnectionInfoRepository = plcConnectionInfoRepository;
            _IElevatorInfoRepository = elevatorInfoRepository;
            _IPlcConnectionStateInfoRepository = plcConnectionStateInfoRepository;
            _PlcReadeDbInfoRepository = plcReadDbInfoRepository;
            _IRunLogInfoService = iRunLogInfoService;
            _logUtil = logUtil;
            _IElevatorMasterInfoRepository = iElevatorMasterInfoRepository;
        }

        public async Task ProcessActionMessageAsync(BytesObjectBase plcActionMessage, BytesObjectBase wcsActionMessage, EquipmentDbObject planarEquipmentDbObject/*, BytesObjectBase plcStateMassge*/)
        {
            var plcMessage = plcActionMessage as PlanarGeneralPlcActionBO;//Plc的动作报文
            var wcsMessage = wcsActionMessage as PlanarGeneralWcsActionBO;//Wcs的动作报文
            //var plcStateBo = plcStateMassge as PlcOnLineStateBO;//Plc在线离线报文 没有设备信息
            plcMessage.PalletBarcode = plcMessage.PalletBarcode.Trim();
            PlanarGeneralWriteWcsAction writeBo = null;//写入Plc的报文
            PlcConnectionS7 plcConn = _PlcConnectionPool.S7GetWritePlcConnection(plcMessage.PlcConnectionID);//plc写入连接（不锁定）


            RunLogInfo runLogInfo = new()
            {
                ContainerBarcode = plcMessage.PalletBarcode,
                EquipmentCode = plcMessage.EquipmentCode,
                RunType = "跨楼层",

                RunLog = "到达十字路口-提升机前任务开始"
            };
            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

            //1. 验证plc是否在线
            var plcIPStates = await _IPlcConnectionStateInfoRepository.GetFirstAsync(l => l.PlcConnectionID == plcMessage.PlcConnectionID && l.Connected == true);
            if (plcIPStates == null)
            {
                runLogInfo.RunLog = $"{plcConn.IP}plc已离线";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                return;
            }

            if (plcMessage.AlrmCode != 0)
            {
                runLogInfo.RunLog = $"报警,报警代码：{plcMessage.AlrmCode}";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                return;
            }
            #region plc写入连接获取&写入报文构建
            //Plc连接Id
            long plcId = wcsMessage.PlcConnectionID;
            //写入plc的报文配置获取
            var objectType = typeof(PlanarGeneralWriteWcsAction).Name;
            var writeConfig = await _PlcWriteDbInfoRepository.GetFirstAsync(s => s.EquipmentCode == plcMessage.EquipmentCode && s.ObjectType == objectType);
            if (writeConfig == null)
            {
                runLogInfo.RunLog = $"获取PLC写入配置失败";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                return;
            }

            //构建写入报文
            writeBo = new PlanarGeneralWriteWcsAction(
                writeConfig.PlcConnectionId,
                writeConfig.ID,
                writeConfig.DbCode,
                writeConfig.DbStart,
                objectType,
                //writeConfig.EquipmentCode.ToInt32(),
                plcMessage.EquipmentCode.ToInt32(),
                plcMessage.ActionType,
                plcMessage.ToEquipmentCode,
                taskCode: plcMessage.TaskCode,
                palletBarcode: plcMessage.PalletBarcode,
                plcMessage.PalletType,
                alrmCode: plcMessage.AlrmCode);

            if (plcConn == null)
            {
                runLogInfo.RunLog = $"获取PLC连接失败";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                return;
            }
            #endregion

            //3. 验证wcs任务，验证wcs当前子任务
            var exp = Expressionable.Create<WorkTaskInfo>();
            exp.AndIF(plcMessage.TaskCode > 0, it => it.TaskCode == plcMessage.TaskCode);
            exp.AndIF(true, it => it.PalletCode == plcMessage.PalletBarcode && it.TaskState == EnumTaskState.Executing);
            var task = await _WorkTaskInfoRepository.GetFirstAsync(exp.ToExpression());
            if (task == null)
            {
                runLogInfo.RunLog = $"任务号({plcMessage.TaskCode})执行中的任务数据未查到";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");

                writeBo.ActionType = 99;
                writeBo.AlrmCode = 7;
                var writeflag = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());
                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                //if (writeflag == false)
                //{
                //    runLogInfo.RunLog = $"无任务报警：设备编号{writeBo.EquipmentCode})写入报文失败";
                //    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                //    _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                //}
                //else
                //{
                //    runLogInfo.RunLog = $"无任务报警：设备编号{writeBo.EquipmentCode})写入报文成功";
                //    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                //}
                return;
            }

            ////获取托盘类型 TODO新的托盘类型接口和写入  20240510 先注释现场环境暂时不支持这样修改
            //Zocono.WCS.WMSApiDomain.WebApi.HeaderResult<int> palletTypeInfo = await WCSMessageWithWMSApi.WCSGetPallentTypeAsync(plcMessage.PalletBarcode, plcMessage.EquipmentCode);

            //if (!palletTypeInfo.IsSucceed)
            //{
            //    runLogInfo.RunLog = $"请求托盘【{plcMessage.PalletBarcode}】类型失败！请查看接口信息！";
            //    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
            //    _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
            //    return;
            //}

            //var palletAB = task.PalletCode.Substring(1, 1);
            //if (palletAB == "A")
            //{
            //    if (palletTypeInfo.Result == 1)
            //    {
            //        writeBo.PalletType = 4;
            //    }
            //    else
            //    {
            //        writeBo.PalletType = 2;
            //    }
            //}
            //else if (palletAB == "B")
            //{
            //    if (palletTypeInfo.Result == 1)
            //    {
            //        writeBo.PalletType = 3;
            //    }
            //    else
            //    {
            //        writeBo.PalletType = 1;
            //    }
            //}
            //else
            //{
            //    if (palletTypeInfo.Result == 1)
            //    {
            //        writeBo.PalletType = 0;
            //    }
            //    else
            //    {
            //        writeBo.PalletType = 0;
            //    }
            //}

            //托盘类型
            switch (task.PalletCode.Substring(1, 1))
            {
                case "A":
                    writeBo.PalletType = 2;
                    break;
                case "B":
                    writeBo.PalletType = 1;
                    break;
                case "C":
                    writeBo.PalletType = 3;
                    break;
            }

            var routeDetailExp = Expressionable.Create<RouteDetailInfo>();
            routeDetailExp.AndIF(true, l => l.ID == task.CurrentRounteDetailID);
            var routeDetail = await _WorkTaskInfoRepository.AsSugarClient()
                .Queryable<RouteDetailInfo>()
                .Where(routeDetailExp.ToExpression())
                .Select(l => l)
                .FirstAsync();

            if (routeDetail == null)
            {
                runLogInfo.RunLog = $"巷道路径详情配置信息起始工位{task.WmsFromStation}目标工位{task.WmsToStation}获取设备路径失败";
                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                return;
            }

            //一楼分选后出来经过一层线体请求提升机TODO 下面使用查询数据库
            string crossEquipmentCodes = JsonConfigurationHelper.GetJson("appsettings.json", "CrossEquipmentCodes");
            _logUtil.Info($"获取到十字口设备配置；{crossEquipmentCodes}");
            //直接获取提升机十字口配置信息列表
            var elevtorMasterList = await _IElevatorMasterInfoRepository.GetListAsync();
            //拿到列表十字口设备号集合
            var crossEqCodeList = elevtorMasterList.Select(it=>it.CrossroadEquipmentCode).ToList();
            //手动写死TODO 后续不使用
            string[] floor11CrossEq = { "110218", "110212", "110210", "110206", "110200" };

            if (crossEqCodeList.Contains(plcMessage.EquipmentCode))
            {
                try
                {
                    //获取所有的读DB配置数据
                    var readPlcDBConfigInfo = await _PlcReadeDbInfoRepository.GetListAsync();
                    //当前交互十字口配置信息
                    ElevatorMasterInfo currentEleCrossInfo = elevtorMasterList.Find(it => it.CrossroadEquipmentCode == plcMessage.EquipmentCode);//await _IElevatorMasterInfoRepository.GetFirstAsync(it => it.CrossroadEquipmentCode == plcMessage.EquipmentCode);
                    if (currentEleCrossInfo == null)
                    {
                        writeBo.ActionType = 99;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】没有找到配置数据！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    //当前交互十字口对应的提升机设备信息
                    ElevatorInfo currentEleInfo = await _IElevatorInfoRepository.GetFirstAsync(it => it.ElevatorCode == currentEleCrossInfo.ElevatorCode);
                    if (currentEleInfo == null)
                    {
                        writeBo.ActionType = 99;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】没有找到配置数据！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    if (!currentEleInfo.IsOpen)
                    {
                        var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                        if (canToNext)
                        {
                            writeBo.ActionType = 12;
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】停止使用！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 18;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】已无路可走！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        return;
                    }
                    if (!currentEleCrossInfo.IsEnable)
                    {
                        var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                        if (canToNext)
                        {
                            writeBo.ActionType = 12;
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】当前层停止使用！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 18;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】已无路可走！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        return;
                    }
                    //查看提升机十字口是否支持当前目标位路径
                    if (!currentEleCrossInfo.CanToEquipments.Contains(task.CurrentToEquipment))
                    {
                        var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                        if (canToNext)
                        {
                            writeBo.ActionType = 12;
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】不支持去目标位【{task.CurrentToEquipment}】";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 18;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】不支持去目标位【{task.CurrentToEquipment}】且已无路可走！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        //writeBo.ActionType = 99;
                        //writeBo.AlrmCode = 150;
                        ////如果找不到则报警了
                        //runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】不支持去目标位【{task.CurrentToEquipment}】！";
                        //_logUtil.Error(runLogInfo.RunLog);
                        //await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    //byte[] byteCurrentElevator = new byte[96];  //提升机报文Byte
                    PlcReadDbInfo plcReadDbEle = null;         //提升机plc读配置
                                                               //获取提升机读DB配置
                    plcReadDbEle = readPlcDBConfigInfo.Find(l => l.EquipmentCode == currentEleCrossInfo.ElevatorCode);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.EquipmentCode == currentEleCrossInfo.ElevatorCode);
                    if (plcReadDbEle == null)
                    {
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 151;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】没有找到读DB配置数据！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    //获取提升机连接对象
                    PlcConnectionS7 plcElevatorConn = _PlcConnectionPool.S7GetWritePlcConnection(plcReadDbEle.PlcConnectionID);
                    if (plcElevatorConn == null)
                    {
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 151;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】没有找到连接池对象！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    //读取数据
                    byte[] byteCurrentElevator = await plcElevatorConn.ReadDbAsync(plcReadDbEle.DbCode, plcReadDbEle.DbStart, plcReadDbEle.DbLength);
                    if (byteCurrentElevator == null)
                    {
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 152;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机DB数据失败！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                    //序列化报文  当前提升机
                    ElevatorGeneralPlcActionBO plcActionBOCurrentElevator = new();
                    plcActionBOCurrentElevator.Serialize(plcReadDbEle.PlcConnectionID, plcReadDbEle.ID, plcReadDbEle.DbStart, plcReadDbEle.DbLength, plcReadDbEle.DbStart, plcReadDbEle.DbLength, "ElevatorGeneralPlcActionBO", plcReadDbEle.EquipmentCode, byteCurrentElevator);//主要是bytes转化成明文

                    //提升机忙  手动 报警状态 都不分配过去
                    if (plcActionBOCurrentElevator.Busy || !plcActionBOCurrentElevator.Auto || plcActionBOCurrentElevator.LiftAlrm)
                    {
                        var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                        if (canToNext)
                        {
                            writeBo.ActionType = 12;
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】状态忙或者手动或者报警！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 18;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】已无路可走！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        }
                        return;
                    }

                    //判断十字口提升机入口托盘状态
                    if (currentEleCrossInfo.ElevatorPUCode != "0")
                    {
                        //获取十字口入口读DB配置
                        PlcReadDbInfo PUEqReadDBInfo = readPlcDBConfigInfo.Find(it => it.EquipmentCode == currentEleCrossInfo.ElevatorPUCode);//await _PlcReadeDbInfoRepository.GetFirstAsync(it => it.EquipmentCode == currentEleCrossInfo.ElevatorPUCode);
                        if (PUEqReadDBInfo == null)
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 153;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机入口【{currentEleCrossInfo.ElevatorPUCode}】读DB配置失败！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            return;
                        }
                        //获取提升机入口连接对象
                        PlcConnectionS7 plcElevatorPuConn = _PlcConnectionPool.S7GetWritePlcConnection(PUEqReadDBInfo.PlcConnectionID);
                        if (plcElevatorPuConn == null)
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 154;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机入口【{currentEleCrossInfo.ElevatorPUCode}】连接配置失败！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            return;
                        }

                        //读取数据 提升机入口
                        byte[] byteCurrentElevatorPu = await plcElevatorPuConn.ReadDbAsync(PUEqReadDBInfo.DbCode, PUEqReadDBInfo.DbStart, PUEqReadDBInfo.DbLength);
                        if (byteCurrentElevatorPu == null)
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 155;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机入口【{currentEleCrossInfo.ElevatorPUCode}】DB数据失败！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            return;
                        }

                        PlanarGeneralPlcActionBO plcActionCurrentElevatorPU = new();
                        plcActionCurrentElevatorPU.Serialize(PUEqReadDBInfo.PlcConnectionID, PUEqReadDBInfo.ID, PUEqReadDBInfo.DbStart, PUEqReadDBInfo.DbLength, PUEqReadDBInfo.DbStart, PUEqReadDBInfo.DbLength, "PlanarGeneralPlcActionBO", PUEqReadDBInfo.EquipmentCode, byteCurrentElevatorPu);//主要是bytes转化成明文
                        if (plcActionCurrentElevatorPU.PalletBarcode.Trim() != "")
                        {
                            var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                            if (canToNext)
                            {
                                writeBo.ActionType = 12;
                                runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】入口【{currentEleCrossInfo.ElevatorPUCode}】有料在！！";
                                _logUtil.Error(runLogInfo.RunLog);
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            }
                            else
                            {
                                writeBo.ActionType = 99;
                                writeBo.AlrmCode = 18;
                                //如果找不到则报警了
                                runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】已无路可走！";
                                _logUtil.Error(runLogInfo.RunLog);
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            }
                            return;
                        }
                    }

                    //获取可去目标位设置  130385-130067-130187|320051-320083-320105-320119|420061-420097-420125-420141
                    var tagEqs = currentEleCrossInfo.CanToEquipments.Split('|');
                    //获取出口目标位  130385-130067-130187
                    var tagPus = tagEqs.Where(it => it.Contains(task.CurrentToEquipment)).FirstOrDefault();
                    //获取当前任务提升机出口设备号
                    if (tagPus != null)
                    {
                        //提升机出口设备号
                        var tagPuEqment = tagPus.Split("-").FirstOrDefault();
                        if (tagPuEqment != "0" && tagPuEqment != null)
                        {
                            //获取出口读DB配置
                            PlcReadDbInfo tagEqReadDBInfo = readPlcDBConfigInfo.Find(it => it.EquipmentCode == tagPuEqment);//await _PlcReadeDbInfoRepository.GetFirstAsync(it => it.EquipmentCode == tagPuEqment);
                            if (tagEqReadDBInfo == null)
                            {
                                writeBo.ActionType = 99;
                                writeBo.AlrmCode = 153;
                                //如果找不到则报警了
                                runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机出口【{tagPuEqment}】读DB配置失败！";
                                _logUtil.Error(runLogInfo.RunLog);
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                return;
                            }
                            //获取提升机出口连接对象
                            PlcConnectionS7 plcElevatorTagPuConn = _PlcConnectionPool.S7GetWritePlcConnection(tagEqReadDBInfo.PlcConnectionID);
                            if (plcElevatorTagPuConn == null)
                            {
                                writeBo.ActionType = 99;
                                writeBo.AlrmCode = 154;
                                //如果找不到则报警了
                                runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机出口【{tagPuEqment}】连接配置失败！";
                                _logUtil.Error(runLogInfo.RunLog);
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                return;
                            }

                            //读取数据
                            byte[] byteCurrentElevatorTagPu = await plcElevatorTagPuConn.ReadDbAsync(tagEqReadDBInfo.DbCode, tagEqReadDBInfo.DbStart, tagEqReadDBInfo.DbLength);
                            if (byteCurrentElevatorTagPu == null)
                            {
                                writeBo.ActionType = 99;
                                writeBo.AlrmCode = 155;
                                //如果找不到则报警了
                                runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机出口【{tagPuEqment}】DB数据失败！";
                                _logUtil.Error(runLogInfo.RunLog);
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                return;
                            }
                            PlanarGeneralPlcActionBO plcActionCurrentElevatorTagPU = new();
                            plcActionCurrentElevatorTagPU.Serialize(tagEqReadDBInfo.PlcConnectionID, tagEqReadDBInfo.ID, tagEqReadDBInfo.DbStart, tagEqReadDBInfo.DbLength, tagEqReadDBInfo.DbStart, tagEqReadDBInfo.DbLength, "PlanarGeneralPlcActionBO", tagEqReadDBInfo.EquipmentCode, byteCurrentElevatorTagPu);//主要是bytes转化成明文
                            if (plcActionCurrentElevatorTagPU.PalletBarcode.Trim() != "")
                            {
                                var canToNext = GetNextEleCanGo(elevtorMasterList, plcMessage.EquipmentCode, currentEleCrossInfo, currentEleInfo, task.CurrentToEquipment);
                                if (canToNext)
                                {
                                    writeBo.ActionType = 12;
                                    runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】出口【{tagPuEqment}】有料在！！";
                                    _logUtil.Error(runLogInfo.RunLog);
                                    await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                }
                                else
                                {
                                    writeBo.ActionType = 99;
                                    writeBo.AlrmCode = 18;
                                    //如果找不到则报警了
                                    runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】已无路可走！";
                                    _logUtil.Error(runLogInfo.RunLog);
                                    await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                }
                                return;
                            }
                            else
                            {
                                writeBo.ActionType = 11;
                                await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                                return;
                            }
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 156;
                            //如果找不到则报警了
                            runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机出口找不到！";
                            _logUtil.Error(runLogInfo.RunLog);
                            await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                            return;
                        }
                    }
                    else
                    {
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 157;
                        //如果找不到则报警了
                        runLogInfo.RunLog = $"十字口【{plcMessage.EquipmentCode}】对应提升机【{currentEleCrossInfo.ElevatorCode}】读取提升机出口目标【{task.CurrentToEquipment}】配置找不到！";
                        _logUtil.Error(runLogInfo.RunLog);
                        await WriteDBToPlcEle(task, writeBo, plcMessage, plcConn, runLogInfo);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    _logUtil.Error($"十字口新规则报错内容：ex={ex.Message}");
                    _logUtil.Error($"十字口新规则报错堆栈：ex={ex.StackTrace}");
                }
            }

            //20231130 新增三楼一层去2楼排出口 由于线路不通 只能从 1 2 3 4 5提升机下去
            string[] floor31DD = { "310141", "310127", "310111", "310097", "310089", "310075", "310061", 
                                    "310167", "310151", "310133", "310117", "310105", "310091", "310075" };
            if (floor31DD.Contains(plcMessage.EquipmentCode) && (task.CurrentToEquipment == "210107" || task.CurrentToEquipment == "110234"))
            {
                runLogInfo.RunLog = $"三楼一层去往二楼排出口以及空盘供应一楼自动分选由于路线走不通，只能从1-5号提升机下去！十字口【{plcMessage.EquipmentCode}】去往排出口【{task.CurrentToEquipment}】";
                writeBo.ActionType = 12;
            }
            else
            {
                //跨楼层主要处理
                //if (task.CurrentFromEquipment.Substring(0, 1) != task.CurrentToEquipment.Substring(0, 1))//可去掉判断
                //{
                    runLogInfo.RunLog = $"跨楼层任务";
                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                    try
                    {
                        if (plcMessage != null)
                        {
                            runLogInfo.RunLog = $"提升机业务plc 报文 读DB = " + plcMessage.PlcReadDbID;
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                        }

                    //获取所有的读DB配置数据
                    var readPlcDBConfigInfo = await _PlcReadeDbInfoRepository.GetListAsync();
                    //if (wcsMessage != null)
                    //{
                    //    runLogInfo.RunLog = $"提升机业务wcs 报文" + JsonConvert.SerializeObject(wcsMessage);
                    //    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                    //}

                    PlcConnectionS7 plcNextElevator;
                        PlcConnectionS7 plcNextLine;
                        byte[] byteNextElevator = new byte[96];
                        byte[] byteNextLine = new byte[40];
                        PlcConnectionStateInfo plcnextIPStates = new();
                        PlcReadDbInfo plcConfigNextPU = new();
                        PlcReadDbInfo plcConfigNextEle = new();
                        PlcReadDbInfo plcConfigDO = new();//出机台plc读配置

                        PlcReadDbInfo plcConfigDD = new();//十字路口plc读配置
                        PlcReadDbInfo plcConfigEle = new();//提升机plc读配置
                        PlcReadDbInfo plcConfigPU = new(); //入机台plc读配置
                        ElevatorInfo eleEquip = new();//提升机管理配置
                        ElevatorJudgeInfo eleNextEquip = new();//提升机绑定配置
                        ElevatorInfo eleNextEquipState = new();//下一个提升机管理配置
                        try
                        {
                        //十字路口plc读配置
                        plcConfigDD = readPlcDBConfigInfo.Find(l => l.ID == plcMessage.PlcReadDbID);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.ID == plcMessage.PlcReadDbID);
                        }
                        catch (Exception e)
                        {
                            _logUtil.Error($"十字路口plc读配置失败，对应对象名plcConfigDD,捕获异常错误信息：{e.Message}");
                            throw;
                        }

                        try
                        {
                        //提升机plc读配置
                        plcConfigEle = readPlcDBConfigInfo.Find(l => l.EquipmentCode == plcConfigDD.PlcName);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.EquipmentCode == plcConfigDD.PlcName);
                        }
                        catch (Exception e)
                        {
                            _logUtil.Error($"提升机plc读配置失败，对应对象名plcConfigEle，捕获异常错误信息：{e.Message}");
                            throw;
                        }

                        try
                        {
                            //出机台plc读配置
                            if (plcMessage.ToEquipmentCode.ToString().Substring(0, 1) == "1")
                            {
                            plcConfigDO = readPlcDBConfigInfo.Find(l => l.PlcName == $"DO{plcConfigEle.EquipmentCode}" && l.EquipmentCode.Contains("130"));//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.PlcName == $"DO{plcConfigEle.EquipmentCode}" && l.EquipmentCode.Contains("130"));
                            }
                            else
                            {
                            plcConfigDO = readPlcDBConfigInfo.Find(l => l.PlcName == $"DO{plcConfigEle.EquipmentCode}" && l.EquipmentCode.Contains(task.CurrentToEquipment.Substring(0, 3)));//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.PlcName == $"DO{plcConfigEle.EquipmentCode}" && l.EquipmentCode.Contains(task.CurrentToEquipment.Substring(0, 3)));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logUtil.Error($"出机台plc读配置失败，对应对象名plcConfigDO，捕获异常错误信息：{ex.Message}");
                            throw;
                        }

                        try
                        {
                        //入机台plc读配置
                        plcConfigPU = readPlcDBConfigInfo.Find(l => l.PlcName == plcMessage.EquipmentCode);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.PlcName == plcMessage.EquipmentCode);
                        }
                        catch (Exception ex)
                        {
                            _logUtil.Error($"入机台plc读配置失败，对应对象名plcConfigPU，捕获异常错误信息：{ex.Message}");
                            throw;
                        }

                        try
                        {
                            //提升机管理配置
                            eleEquip = await _IElevatorInfoRepository.GetFirstAsync(l => l.ElevatorCode == plcConfigEle.EquipmentCode);
                        }
                        catch (Exception ex)
                        {
                            _logUtil.Error($"提升机管理配置读取失败，对应对象名eleEquip，捕获异常错误信息：{ex.Message}");
                            throw;
                        }

                        try
                        {
                            //提升机绑定配置
                            eleNextEquip = await _IElevatorJudgeInfoRepository.GetFirstAsync(l => l.JudgeEquipmentCode == plcMessage.EquipmentCode);
                        }
                        catch (Exception ex)
                        {
                            _logUtil.Error($"提升机绑定配置读取失败，对应对象名eleNextEquip，捕获异常错误信息：{ex.Message}");
                            throw;
                        }

                        try
                        {
                            //下一个提升机管理配置（如果下一提升机为0加判断）
                            eleNextEquipState = await _IElevatorInfoRepository.GetFirstAsync(l => l.ElevatorCode == eleNextEquip.NextElevatorCode);
                        }
                        catch (Exception ex)
                        {
                            _logUtil.Error($"下一个提升机管理配置读取失败，对应对象名eleNextEquipState，捕获异常错误信息：{ex.Message}");
                            throw;
                        }


                        if (eleNextEquipState != null)
                        {
                            try
                            {
                            plcConfigNextEle = readPlcDBConfigInfo.Find(l => l.EquipmentCode == eleNextEquipState.ElevatorCode);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.EquipmentCode == eleNextEquipState.ElevatorCode);//下一提升机plc配置
                            }
                            catch (Exception ex)
                            {
                                _logUtil.Error($"下一提升机plc配置获取失败，对应对象名plcConfigNextEle，异常捕获错误信息：{ex.Message}");
                                throw;
                            }
                        }

                        if (eleNextEquip != null)
                        {
                            try
                            {
                            plcConfigNextPU = readPlcDBConfigInfo.Find(l => l.EquipmentCode == eleNextEquip.NextEquipmentPU);//await _PlcReadeDbInfoRepository.GetFirstAsync(l => l.EquipmentCode == eleNextEquip.NextEquipmentPU);//下一提升机入机台
                            }
                            catch (Exception ex)
                            {
                                _logUtil.Error($"下一提升机入机台配置获取失败，对应对象名plcConfigNextPU，异常捕获错误信息：{ex.Message}");
                                throw;
                            }
                        }

                        if (eleNextEquip.IsNextBothway)
                        {
                            if (plcConfigNextPU.PlcConnectionID != plcMessage.PlcConnectionID)
                            {
                                plcNextLine = _PlcConnectionPool.S7GetWritePlcConnection(plcConfigNextPU.PlcConnectionID);
                            }
                            else
                            {
                                plcNextLine = _PlcConnectionPool.S7GetWritePlcConnection(plcMessage.PlcConnectionID);
                            }
                            if (plcNextLine == null)
                            {
                                runLogInfo.RunLog = $"处理失败：获取下一线体连接池失败，请确认是否有添加{plcConfigNextPU.EquipmentCode}";
                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                                return;
                            }
                            byteNextLine = await plcNextLine.ReadDbAsync(plcConfigNextPU.DbCode, plcConfigNextPU.DbStart, plcConfigNextPU.DbLength);
                            if (byteNextLine == null)
                            {
                                runLogInfo.RunLog = $"读正反转下一入机台DB失败";
                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                                return;
                            }

                        }

                        PlcConnectionS7 plcElevator = _PlcConnectionPool.S7GetWritePlcConnection(plcConfigEle.PlcConnectionID);

                        PlcConnectionS7 plcDo = _PlcConnectionPool.S7GetWritePlcConnection(plcConfigDO.PlcConnectionID);

                        if (plcElevator == null)
                        {
                            runLogInfo.RunLog = $"处理失败：获取楼层提升机plc连接池失败，请确认是否掉线";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                            //return;
                        }
                        if (plcDo == null)
                        {
                            runLogInfo.RunLog = $"处理失败：获取目标出机台PLC连接失败，请确认是否掉线";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                            //return;
                        }

                        //下一正反转提升机
                        if (eleNextEquip.IsNextBothway)
                        {
                            if ((eleEquip.Number <= 8 && eleNextEquipState.Number > 8) || (eleEquip.Number > 8 && eleNextEquipState.Number <= 8))
                            {
                                if (eleNextEquipState.IsOpen && !eleNextEquipState.IsEnd)
                                {
                                    //1. 验证plc是否在线
                                    plcnextIPStates = await _IPlcConnectionStateInfoRepository.GetFirstAsync(l => l.PlcConnectionID == plcConfigNextEle.PlcConnectionID && l.Connected == true);
                                    if (plcIPStates == null)
                                    {
                                        runLogInfo.RunLog = $"{plcConn.IP}plc已离线";
                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                        _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                                        //return;
                                    }
                                    else
                                    {
                                        plcNextElevator = _PlcConnectionPool.S7GetWritePlcConnection(plcConfigNextEle.PlcConnectionID);

                                        byteNextElevator = await plcNextElevator.ReadDbAsync(plcConfigNextEle.DbCode, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength);
                                        if (byteNextElevator == null)
                                        {
                                            runLogInfo.RunLog = $"读DB失败";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                                            return;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                byteNextElevator = await plcElevator.ReadDbAsync(plcConfigNextEle.DbCode, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength);
                                if (byteNextElevator == null)
                                {
                                    runLogInfo.RunLog = $"读DB失败";
                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                    _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                                    return;
                                }
                            }
                        }

                        //正反转下一入库台
                        //if (eleNextEquip.IsNextBothway)
                        //{
                        //    byteNextLine = await plcNextLine.ReadDbAsync(plcConfigNextPU.DbCode, plcConfigNextPU.DbStart, plcConfigNextPU.DbLength);
                        //    if (byteNextLine == null)
                        //    {
                        //        runLogInfo.RunLog = $"读正反转下一入机台DB失败";
                        //        await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                        //        return;
                        //    }
                        //}

                        //入库台
                        byte[] bytesPu = await plcConn.ReadDbAsync(plcConfigPU.DbCode, plcConfigPU.DbStart, plcConfigPU.DbLength);
                        if (bytesPu == null)
                        {
                            runLogInfo.RunLog = $"读入机台DB失败";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                            return;
                        }

                        //当前提升机
                        byte[] bytes = await plcElevator.ReadDbAsync(plcConfigEle.DbCode, plcConfigEle.DbStart, plcConfigEle.DbLength);
                        if (bytes == null)
                        {
                            runLogInfo.RunLog = $"读当前提升机DB失败查看是否离线";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                            return;
                        }

                        //目标出库台
                        byte[] bytesdo = await plcDo.ReadDbAsync(plcConfigDO.DbCode, plcConfigDO.DbStart, plcConfigDO.DbLength);
                        if (bytesdo == null)
                        {
                            runLogInfo.RunLog = $"读目标出库台DB失败查看是否离线";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _logUtil.Error($"到达十字口：【{plcMessage.EquipmentCode}】{runLogInfo.RunLog}");
                            return;
                        }

                        PlanarGeneralPlcActionBO plcActionPU = new();
                        plcActionPU.Serialize(plcConfigPU.PlcConnectionID, plcConfigPU.ID, plcConfigPU.DbStart, plcConfigPU.DbLength, plcConfigPU.DbStart, plcConfigPU.DbLength, "PlanarGeneralPlcActionBO", plcConfigPU.EquipmentCode, bytesPu);//主要是bytes转化成明文


                        PlanarGeneralPlcActionBO plcActionNextPU = new();
                        if (eleNextEquip.IsNextBothway)
                        {
                            plcActionNextPU.Serialize(plcConfigNextPU.PlcConnectionID, plcConfigNextPU.ID, plcConfigNextPU.DbStart, plcConfigNextPU.DbLength, plcConfigNextPU.DbStart
                            , plcConfigNextPU.DbLength, "PlanarGeneralPlcActionBO", plcConfigNextPU.EquipmentCode, byteNextLine);//主要是bytes转化成明文
                        }


                        PlanarGeneralPlcActionBO plcActionDO = new();
                        plcActionDO.Serialize(plcConfigDO.PlcConnectionID, plcConfigDO.ID, plcConfigDO.DbStart, plcConfigDO.DbLength, plcConfigDO.DbStart, plcConfigDO.DbLength, "PlanarGeneralPlcActionBO", plcConfigDO.EquipmentCode, bytesdo);//主要是bytes转化成明文


                        ElevatorGeneralPlcActionBO plcActionBO = new();
                        plcActionBO.Serialize(plcConfigEle.PlcConnectionID, plcConfigEle.ID, plcConfigEle.DbStart, plcConfigEle.DbLength, plcConfigEle.DbStart, plcConfigEle.DbLength, "ElevatorGeneralPlcActionBO", plcConfigEle.EquipmentCode, bytes);//主要是bytes转化成明文


                        ElevatorGeneralPlcActionBO plcNextActionBO = new();
                        //双向
                        if (eleNextEquip.IsNextBothway)
                        {
                            plcNextActionBO.Serialize(plcConfigNextEle.PlcConnectionID, plcConfigNextEle.ID, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength
                                , "ElevatorGeneralPlcActionBO", plcConfigNextEle.EquipmentCode, byteNextElevator);//主要是bytes转化成明文

                            plcNextActionBO.Serialize(plcConfigNextEle.PlcConnectionID, plcConfigNextEle.ID, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength, plcConfigNextEle.DbStart, plcConfigNextEle.DbLength
                                , "ElevatorGeneralPlcActionBO", plcConfigNextEle.EquipmentCode, byteNextElevator);//主要是bytes转化成明文

                        }

                        //还要判断出口是否有托盘占用
                        try
                        {
                            if (eleNextEquipState == null && eleNextEquip.NextElevatorCode == "1")
                            {
                                eleNextEquipState = new();
                                eleNextEquipState.IsEnd = false;
                            }
                            if (eleNextEquipState == null && eleNextEquip.NextElevatorCode == "0")
                            {
                                eleNextEquipState = new();
                                eleNextEquipState.IsEnd = true;
                            }
                            //一楼回库回拉线需要小于提升机来分配
                            //当前提升机不能进，要到下一个提升机需要判断下一个口的状态
                            if (task.CurrentFromEquipment.Substring(0, 1) == "1")//1到234
                            {
                                if (!eleNextEquipState.IsEnd)
                                {
                                    if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                    {
                                        if (eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                        {
                                            if (routeDetail.FromCargo.ToInt32() <= plcConfigDD.PlcName.ToInt32() && (routeDetail.ToCargo.ToInt32() > plcConfigDD.PlcName.ToInt32() || routeDetail.ToCargo.ToInt32() == 0))
                                            {
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (plcActionBO.Busy)
                                                        {
                                                            if (plcActionBO.UpMaterial)
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 12;
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 12;
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                            else/* if (plcActionBO.DownMaterial)*/
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 12;
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 12;
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }

                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 11;//允许进入提升机
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }

                                                    }
                                                    else
                                                    {
                                                        //runLogInfo.RunLog = $"提升机报警或不在自动状态或目标出口有料不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 12;
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    }
                                                }
                                                else
                                                {
                                                    writeBo.ActionType = 12;
                                                    runLogInfo.RunLog = $"入机台有料";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(plcActionBO)}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                            }
                                            else if (routeDetail.FromCargo.ToInt32() > plcConfigDD.PlcName.ToInt32())
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：需要往下走才能到达目标位置";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else
                                            {
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (plcActionBO.Busy)
                                                        {
                                                            if (plcActionBO.UpMaterial)
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                            else/* if (plcActionBO.DownMaterial)*/
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }

                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 11;//允许进入提升机
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {

                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 16;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                                else
                                                {

                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 19;
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }


                                            }

                                        }
                                        else if (eleNextEquip.IsEnable && eleNextEquip.IsNextEnd)
                                        {

                                            if (routeDetail.FromCargo.ToInt32() <= plcConfigDD.PlcName.ToInt32() && (routeDetail.ToCargo.ToInt32() > plcConfigDD.PlcName.ToInt32() || routeDetail.ToCargo.ToInt32() == 0))
                                            {
                                                //TODO
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (plcActionBO.Busy)
                                                        {
                                                            if (plcActionBO.UpMaterial)
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                            else/* if (plcActionBO.DownMaterial)*/
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }

                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 11;//允许进入提升机
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {

                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 16;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                                else
                                                {

                                                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 19;
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }
                                            }
                                            else if (routeDetail.FromCargo.ToInt32() > plcConfigDD.PlcName.ToInt32())
                                            {
                                                writeBo.ActionType = 99;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层下一提升机口不通，需要往下走才能到达目标位置";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                writeBo.AlrmCode = 18;
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }
                                            else
                                            {
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (plcActionBO.Busy)
                                                        {
                                                            if (plcActionBO.UpMaterial)
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                            else/* if (plcActionBO.DownMaterial)*/
                                                            {
                                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                {
                                                                    runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                    {
                                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 11;//允许进入提升机
                                                                    }
                                                                }

                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 11;//允许进入提升机
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {

                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 16;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                                else
                                                {

                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 19;
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }
                                            }
                                        }
                                        else if (!eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                        {
                                            if (routeDetail.FromCargo.ToInt32() <= plcConfigDD.PlcName.ToInt32() && (routeDetail.ToCargo.ToInt32() > plcConfigDD.PlcName.ToInt32() || routeDetail.ToCargo.ToInt32() == 0))
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else if (routeDetail.FromCargo.ToInt32() > plcConfigDD.PlcName.ToInt32())
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用，需要往下走才能到达目标位置";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else
                                            {
                                                //此托盘最后一个提升机
                                                writeBo.ActionType = 0;
                                                writeBo.AlrmCode = 15;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用,此托盘的最后路径是这个提升机。";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                        }
                                        else
                                        {
                                            runLogInfo.RunLog = $"{eleNextEquipState.ElevatorCode}：此提升机已禁用，本提升机和下一提升机是终节点，不能往前走，请人工处理此托盘走向";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            writeBo.ActionType = 0;
                                            writeBo.AlrmCode = 16;
                                        }
                                    }
                                    else
                                    {
                                        //本层下一提升机可用
                                        if (!eleNextEquip.IsNextEnd)
                                        {

                                            if (routeDetail.FromCargo.ToInt32() <= plcConfigDD.PlcName.ToInt32() && (routeDetail.ToCargo.ToInt32() > plcConfigDD.PlcName.ToInt32() || routeDetail.ToCargo.ToInt32() == 0))
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else if (routeDetail.FromCargo.ToInt32() > plcConfigDD.PlcName.ToInt32())
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用，需要往下走才能到达目标位置";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else
                                            {
                                                //最后一个提升机直接入
                                                writeBo.ActionType = 0;
                                                writeBo.AlrmCode = 15;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：本楼层此提升机已禁用,此托盘的最后路径是这个提升机。";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                        }
                                        else
                                        {
                                            //最后一个提升机直接入
                                            writeBo.ActionType = 0;
                                            writeBo.AlrmCode = 18;
                                            runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走129";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                        }

                                    }
                                }
                                else
                                {
                                    if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                    {
                                        if (eleNextEquip.IsEnable)
                                        {
                                            if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                            {
                                                if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (plcActionBO.Busy)
                                                    {
                                                        if (plcActionBO.UpMaterial)
                                                        {
                                                            runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                            {
                                                                runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 99;
                                                                writeBo.AlrmCode = 42;
                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            }
                                                            else
                                                            {
                                                                if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                {
                                                                    runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                }
                                                            }
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                        else/* if (plcActionBO.DownMaterial)*/
                                                        {
                                                            runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                            if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                            {
                                                                runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 99;
                                                                writeBo.AlrmCode = 42;
                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            }
                                                            else
                                                            {
                                                                if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                {
                                                                    runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                    writeBo.ActionType = 99;
                                                                    writeBo.AlrmCode = 42;
                                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                }
                                                            }

                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                        }
                                                    }
                                                    else
                                                    {
                                                        runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 11;//允许进入提升机
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    }
                                                }
                                                else
                                                {

                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 16;
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }
                                            }
                                            else
                                            {

                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                runLogInfo.RunLog = $"提升机出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 19;
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }
                                        }
                                        else
                                        {
                                            runLogInfo.RunLog = $"{eleNextEquipState.ElevatorCode}：此提升机已禁用，本提升机和下一提升机是终节点，不能往前走，请人工处理此托盘走向";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            writeBo.ActionType = 99;
                                            writeBo.AlrmCode = 18;
                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                        }

                                    }
                                    else
                                    {
                                        runLogInfo.RunLog = $"{eleNextEquipState.ElevatorCode}：本提升机和下一提升机已禁用，请人工处理此托盘走向";
                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                        writeBo.ActionType = 99;
                                        writeBo.AlrmCode = 18;
                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                    }
                                }
                            }
                            else if ((task.CurrentFromEquipment.Substring(0, 1) == "2") || (task.CurrentFromEquipment.Substring(0, 1).ToInt32() > 2 && task.CurrentToEquipment.Substring(0, 1).ToInt32() < 3))
                            {
                                var fromE = task.CurrentFromEquipment.Trim().Substring(0, 3);
                                var toE = task.CurrentToEquipment.Trim().Substring(0, 3);
                                //下一楼一层
                                if ((fromE == "310"|| fromE == "410" || fromE == "210")&& toE=="110"&&( plcConfigDD.PlcName.ToInt32()== 410003 || plcConfigDD.PlcName.ToInt32() == 410019 || plcConfigDD.PlcName.ToInt32() == 410029))
                                {
                                    runLogInfo.RunLog = $"此提升机到达不了目标位，不允许进入提升机{plcActionBO.EquipmentCode}";
                                    writeBo.ActionType = 12;
                                }
                                else
                                {
                                    if (!eleNextEquipState.IsEnd)
                                    {
                                        if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                        {
                                            if (eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                            {
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        //先不考虑在做的任务是否也是同一个目标位
                                                        if (eleNextEquip.IsThisBothway)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 12;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    //runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }

                                                        }
                                                        else
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 12;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 12;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }

                                                    }
                                                    else
                                                    {
                                                        //runLogInfo.RunLog = $"提升机报警或不在自动状态或目标出口有料不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 12;
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    }
                                                }
                                                else
                                                {
                                                    runLogInfo.RunLog = $"入库台托盘码{plcActionPU.PalletBarcode}：入库台有料";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    writeBo.ActionType = 12;
                                                }
                                                //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(writeBo)}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            if (eleNextEquip.IsEnable && eleNextEquip.IsNextEnd)
                                            {

                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        //先不考虑在做的任务是否也是同一个目标位
                                                        if (eleNextEquip.IsThisBothway)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，但此托盘只有此提升机可走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，但此托盘只有此提升机可走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }

                                                        }
                                                        else
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }

                                                        }

                                                    }
                                                    else
                                                    {
                                                        //runLogInfo.RunLog = $"提升机报警或不在自动状态或目标出口有料不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}，下一提升机被禁用此托盘只能进入此提升机需等待";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 16;
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                                else
                                                {
                                                    runLogInfo.RunLog = $"入库台托盘码{plcActionPU.PalletBarcode}：入库台有料，下一提升机被禁用此托盘只能进入此提升机需等待";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 19;
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }
                                                //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(writeBo)}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            if (!eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                            {
                                                runLogInfo.RunLog = $"往下一提升机走";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{JsonConvert.SerializeObject(writeBo)}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            if (!eleNextEquip.IsEnable && eleNextEquip.IsNextEnd)
                                            {
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走13";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }

                                        }
                                        else
                                        {
                                            if (!eleNextEquip.IsNextEnd)
                                            {
                                                writeBo.ActionType = 12;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：此提升机已禁用";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            }
                                            else
                                            {
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走14{JsonConvert.SerializeObject(eleEquip)}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }

                                        }
                                    }
                                    else
                                    {
                                        if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                        {
                                            if (eleNextEquip.IsEnable)
                                            {
                                                if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                {
                                                    if (plcActionDO.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (eleNextEquip.IsThisBothway)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 16;//等待目标出口无料
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 16;//等待目标出口无料
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (plcActionBO.UpMaterial)
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 16;//等待目标出口无料
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                                else/* if (plcActionBO.DownMaterial)*/
                                                                {
                                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    if (plcActionBO.DownToEquipmentCode == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                    {
                                                                        runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                        writeBo.ActionType = 99;
                                                                        writeBo.AlrmCode = 42;
                                                                         _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                        {
                                                                            runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，当前提升机正在往此托盘目标位走";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 11;//允许进入提升机
                                                                        }
                                                                    }

                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"2入机台无料{plcActionPU.PalletBarcode}，出机台无料{plcActionDO.PalletBarcode}，允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }

                                                    }
                                                    else
                                                    {
                                                        runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，出口有料";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 16;//等待目标出口无料
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                                else
                                                {

                                                    runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，入口有料";
                                                    writeBo.ActionType = 99;
                                                    writeBo.AlrmCode = 19;//等待目标入口无料
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                }


                                            }
                                            else
                                            {
                                                runLogInfo.RunLog = $"{eleNextEquipState.ElevatorCode}：此提升机已禁用，本提升机和下一提升机是终节点，不能往前走，请人工处理此托盘走向";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }
                                        }
                                        else
                                        {
                                            runLogInfo.RunLog = $"{eleNextEquipState.ElevatorCode}：此提升机已禁用，本提升机和下一提升机是终节点，不能往前走，请人工处理此托盘走向";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            writeBo.ActionType = 99;
                                            writeBo.AlrmCode = 18;
                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                        }
                                    }
                                }
                            }//其他楼层(3,4到1，2)和（2到3，4）
                            else
                            {   //3,4之间流转
                                //3楼三层上4楼三层不用12号提升机
                                if (plcMessage.EquipmentCode == "330143" && plcMessage.ToEquipmentCode.ToString().Substring(0, 3) == "430")
                                {
                                    runLogInfo.RunLog = $"防止冲突不允许进入提升机{plcActionBO.EquipmentCode}";
                                    writeBo.ActionType = 12;
                                }//3楼三层上4楼三层除了去4楼八号巷道的其余都不使用11号提升机
                                else if (plcMessage.EquipmentCode == "330129" && plcMessage.ToEquipmentCode.ToString().Substring(0, 3) == "430" && plcMessage.ToEquipmentCode.ToString() != "430157")
                                {
                                    runLogInfo.RunLog = $"防止冲突不允许进入提升机{plcActionBO.EquipmentCode}";
                                    writeBo.ActionType = 12;
                                }
                                else
                                {
                                    if (!eleNextEquipState.IsEnd)
                                    {
                                        if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                        {
                                            if (eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                            {
                                                //小于PlcName能往前走等于
                                                if (routeDetail.FromCargo.ToInt32() < plcConfigDD.PlcName.ToInt32() || routeDetail.FromCargo.ToInt32() == 0)
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            //先不考虑在做的任务是否也是同一个目标位
                                                            if (eleNextEquip.IsThisBothway)
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 12;
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 12;
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }

                                                            }
                                                            else
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 12;
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                            writeBo.ActionType = 12;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 12;
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            //runLogInfo.RunLog = $"提升机报警或不在自动状态或目标出口有料不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 12;
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        runLogInfo.RunLog = $"提升机入口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 12;
                                                    }
                                                    //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(plcActionBO)}";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                else
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (eleNextEquip.IsThisBothway)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            //runLogInfo.RunLog = $"提升机报警或不在自动状态或目标出口有料不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 99;
                                                            writeBo.AlrmCode = 16;
                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        runLogInfo.RunLog = $"提升机入口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 19;
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                    //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(plcActionBO)}";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                            }
                                            if (eleNextEquip.IsEnable && eleNextEquip.IsNextEnd)
                                            {
                                                if (routeDetail.FromCargo.ToInt32() < plcConfigDD.PlcName.ToInt32() || routeDetail.FromCargo.ToInt32() == 0)
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            //先不考虑在做的任务是否也是同一个目标位
                                                            if (eleNextEquip.IsThisBothway)
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }

                                                            }
                                                            else
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 99;
                                                            writeBo.AlrmCode = 16;
                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        runLogInfo.RunLog = $"提升机入口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 19;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    }
                                                    //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(plcActionBO)}";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                else
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (eleNextEquip.IsThisBothway)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 99;
                                                            writeBo.AlrmCode = 16;
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                        }
                                                    }
                                                    else
                                                    {

                                                        runLogInfo.RunLog = $"提升机入口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 19;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                            }
                                            if (!eleNextEquip.IsEnable && !eleNextEquip.IsNextEnd)
                                            {
                                                if (routeDetail.FromCargo.ToInt32() < plcConfigDD.PlcName.ToInt32() || routeDetail.FromCargo.ToInt32() == 0)
                                                {

                                                    runLogInfo.RunLog = $"当前楼层已禁用此提升机，往下一提升机走";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    writeBo.ActionType = 12;

                                                    runLogInfo.RunLog = $"{JsonConvert.SerializeObject(writeBo)}";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                else
                                                {
                                                    runLogInfo.RunLog = $"此提升机{plcActionBO.EquipmentCode}为此托盘最后的路径，请解除不必要的禁用";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                    writeBo.ActionType = 99;//允许进入提升机
                                                    writeBo.AlrmCode = 15;//允许进入提升机
                                                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));

                                                }
                                            }
                                            if (!eleNextEquip.IsEnable && eleNextEquip.IsNextEnd)
                                            {
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走eleNextEquip.IsNextEnd{eleNextEquip.IsNextEnd},eleNextEquip.IsEnable{eleNextEquip.IsEnable}";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }
                                        }
                                        else
                                        {
                                            if (!eleNextEquip.IsNextEnd)
                                            {
                                                if (routeDetail.FromCargo.ToInt32() == plcConfigDD.PlcName.ToInt32())
                                                {
                                                    writeBo.ActionType = 12;
                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：此提升机已禁用,但这是此托盘的最后一个路径，请人工处理此托盘";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                else
                                                {
                                                    writeBo.ActionType = 12;
                                                    runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：此提升机已禁用";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                            }
                                            else
                                            {

                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走!eleEquip.IsOpen && !eleEquip.IsEnd";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }

                                        }
                                    }
                                    else
                                    {
                                        if (eleEquip.IsOpen && !eleEquip.IsEnd)
                                        {
                                            if (!eleNextEquip.IsEnable)
                                            {
                                                if (routeDetail.FromCargo.ToInt32() < plcConfigDD.PlcName.ToInt32() || routeDetail.FromCargo.ToInt32() == 0)
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            //先不考虑在做的任务是否也是同一个目标位
                                                            if (eleNextEquip.IsThisBothway)
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 00;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }

                                                            }
                                                            else
                                                            {
                                                                if (plcActionBO.Busy)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 18;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，不允许进入提升机{plcActionBO.EquipmentCode},当前楼层前面提升机被禁用，须人工处理";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"不允许进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突，当前楼层前面提升机被禁用，须人工处理";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 42;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                    writeBo.ActionType = 11;//允许进入提升机
                                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {

                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 99;
                                                            writeBo.AlrmCode = 16;
                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 19;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                    //runLogInfo.RunLog = $"{JsonConvert.SerializeObject(plcActionBO)}";
                                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                }
                                                else
                                                {
                                                    if (plcActionPU.PalletBarcode.Trim().Length == 0)
                                                    {
                                                        if (/*!plcActionBO.LiftAlrm &&*//* plcActionBO.Auto &&*/ plcActionDO.PalletBarcode.Trim().Length == 0)
                                                        {
                                                            if (plcActionBO.Busy)
                                                            {
                                                                if (eleNextEquip.IsThisBothway)
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        //runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2) || plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (plcActionBO.UpMaterial)
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}上层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                        if (plcActionBO.UpToEquipmentCode.ToString().Length == 0)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待进入提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }
                                                                    }
                                                                    else/* if (plcActionBO.DownMaterial)*/
                                                                    {
                                                                        runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}下层有料";
                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                                                        if (plcActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                                                                        {
                                                                            runLogInfo.RunLog = $"提升机目标设备号为空，等待进入提升机{plcActionBO.EquipmentCode}";
                                                                            writeBo.ActionType = 99;
                                                                            writeBo.AlrmCode = 42;
                                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (plcActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcActionDO.EquipmentCode.Substring(0, 2))
                                                                            {
                                                                                runLogInfo.RunLog = $"等待提升机{plcActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                                                                                writeBo.ActionType = 99;
                                                                                writeBo.AlrmCode = 18;
                                                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                                            }
                                                                            else
                                                                            {
                                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                            }
                                                                        }

                                                                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                runLogInfo.RunLog = $"允许进入提升机{plcActionBO.EquipmentCode}";
                                                                writeBo.ActionType = 11;//允许进入提升机
                                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            runLogInfo.RunLog = $"提升机目标出口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                            writeBo.ActionType = 99;
                                                            writeBo.AlrmCode = 16;
                                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                        }
                                                    }
                                                    else
                                                    {

                                                        runLogInfo.RunLog = $"提升机入口有料，不允许进入提升机{plcActionBO.EquipmentCode}";
                                                        writeBo.ActionType = 99;
                                                        writeBo.AlrmCode = 19;
                                                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                writeBo.ActionType = 99;
                                                writeBo.AlrmCode = 18;
                                                runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走";
                                                //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                            }
                                        }
                                        else
                                        {
                                            writeBo.ActionType = 99;
                                            writeBo.AlrmCode = 18;
                                            runLogInfo.RunLog = $"{plcActionBO.EquipmentCode}：提升机不可用，此托盘无路可走";
                                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                        }

                                    }
                                }
                            }

                            #region 判断下一提升机
                            //判断下一提升机
                            //if (writeBo.ActionType == 12)
                            //{
                            //    if (eleNextEquip.NextElevatorCode != "0" && eleNextEquip.IsNextBothway)
                            //    {
                            //        //双向
                            //        //if (eleNextEquip.IsNextBothway)
                            //        {
                            //            if (routeDetail.FromCargo == eleNextEquipState.ElevatorCode && plcnextIPStates != null)
                            //            {
                            //                if (eleNextEquipState.IsOpen)
                            //                {
                            //                    runLogInfo.RunLog = $"下一提升机作为最终路径，被禁用，不允许进入下一提升机{plcNextActionBO.EquipmentCode}";
                            //                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            //                    writeBo.ActionType = 0;
                            //                }
                            //                if (plcActionNextPU.PalletBarcode.Trim().Length > 0)
                            //                {
                            //                    runLogInfo.RunLog = $"下一提升机作为最终路径，入料口有料，不允许进入提升机{plcNextActionBO.EquipmentCode}";
                            //                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            //                    writeBo.ActionType = 0;
                            //                }
                            //                else
                            //                {
                            //                    if (plcNextActionBO.Busy)
                            //                    {
                            //                        if (plcNextActionBO.UpMaterial)
                            //                        {
                            //                            runLogInfo.RunLog = $"{plcNextActionBO.EquipmentCode}上层有料";
                            //                            await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            //                            if (plcNextActionBO.UpToEquipmentCode.ToString().Length == 0)
                            //                            {
                            //                                runLogInfo.RunLog = $"下一提升机繁忙但目标设备号为空，不允许进入下一提升机{plcNextActionBO.EquipmentCode}";
                            //                                writeBo.ActionType = 0;
                            //                            }
                            //                            else
                            //                            {
                            //                                if (plcNextActionBO.UpToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2))
                            //                                {
                            //                                    runLogInfo.RunLog = $"不允许进入下提升机{plcNextActionBO.EquipmentCode}，提升机出料目标台与入机台冲突";
                            //                                    writeBo.ActionType = 0;
                            //                                }
                            //                                else
                            //                                {
                            //                                    writeBo.ActionType = 12;//允许进入提升机
                            //                                }
                            //                            }
                            //                            await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            //                        }
                            //                        else/* if (plcActionBO.DownMaterial)*/
                            //                        {
                            //                            runLogInfo.RunLog = $"{plcNextActionBO.EquipmentCode}下层有料";
                            //                            await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                            //                            if (plcNextActionBO.DownToEquipmentCode.ToString().Length == 0/* || plcMessage.EquipmentCode.Length == 0*/)
                            //                            {
                            //                                runLogInfo.RunLog = $"下一提升机繁忙但目标设备号为空，不允许进入下一提升机{plcNextActionBO.EquipmentCode}";
                            //                                writeBo.ActionType = 0;
                            //                            }
                            //                            else
                            //                            {
                            //                                if (plcNextActionBO.DownToEquipmentCode.ToString().Substring(0, 2) == plcMessage.EquipmentCode.Substring(0, 2))
                            //                                {
                            //                                    runLogInfo.RunLog = $"不允许进入下提升机{plcNextActionBO.EquipmentCode}";
                            //                                    writeBo.ActionType = 0;
                            //                                }
                            //                                else
                            //                                {
                            //                                    runLogInfo.RunLog = $"允许进入下提升机{plcNextActionBO.EquipmentCode}";
                            //                                    writeBo.ActionType = 12;//允许进入提升机
                            //                                }
                            //                            }

                            //                            await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                            //                        }
                            //                    }
                            //                }
                            //            }
                            //        }
                            //    }

                            //}
                            #endregion

                        }
                        catch (Exception ex)
                        {
                            runLogInfo.RunLog = $"异常1{ex.Message}";
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 14;
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                            _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                        }

                    }
                    catch (Exception ex)
                    {
                        runLogInfo.RunLog = $"异常2{ex.Message}";
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 14;
                        //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                    }
                //}
                //else
                //{

                //}
            }


            //写入正常报文
            writeBo.TaskCode = task.TaskCode;
            writeBo.PalletBarcode = task.PalletCode;
            writeBo.ToEquipmentCode = task.CurrentToEquipment.ToInt32();
            var writeBl = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());

            if (!writeBl)
            {
                runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机写入正常报文失败，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
            }
            else
            {
                if (writeBo.ActionType == 11)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机允许进入写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
                else if (writeBo.ActionType == 12)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机不允许进入原因：【{runLogInfo.RunLog}】;写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
                else if (writeBo.ActionType == 99)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机进入报错原因：【{runLogInfo.RunLog}】;写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
            }
            return;


        }


        /// <summary>
        /// 判断接下来十字口是否可用到达现有目标设备
        /// </summary>
        /// <param name="elevatorMasterInfos">十字口配置集合</param>
        /// <param name="crossEqument">当前十字口设备号</param>
        /// <param name="currentEleCrossInfo">当前十字口配置</param>
        /// <param name="currentEleInfo">当前提升机配置</param>
        /// <param name="currentToEqment">当前目标设备号</param>
        /// <returns></returns>
        public bool GetNextEleCanGo(List<ElevatorMasterInfo> elevatorMasterInfos, string crossEqument, ElevatorMasterInfo currentEleCrossInfo, ElevatorInfo currentEleInfo, string currentToEqment)
        {
            bool canGo = false;
            //如果没有下一十字口则直接返回false
            if (currentEleCrossInfo.NextElevatorCodes == "0")
            {
                _logUtil.Info($"十字口【{crossEqument}】,没有下一个十字口配置");
                return false;
            }
            //如果接下来的十字口可用到达目标设备则可用往下走
            string[] nextCodes = currentEleCrossInfo.NextElevatorCodes.Split(',');
            foreach (string nextCode in nextCodes)
            {
                var canNext = elevatorMasterInfos.Where(it=>it.CrossroadEquipmentCode == nextCode && it.CanToEquipments.Contains(currentToEqment) && it.IsEnable).ToList();
                if (canNext.Count > 0)
                {
                    _logUtil.Info($"十字口【{crossEqument}】,有下一个十字口可以到达目标设备");
                    return true;
                }
            }
            _logUtil.Info($"十字口【{crossEqument}】,没有下一个十字口可以到达目标设备");
            return canGo;
        }

        /// <summary>
        /// 写入PLC方法
        /// </summary>
        /// <param name="task"></param>
        /// <param name="writeBo"></param>
        /// <param name="plcMessage"></param>
        /// <param name="plcConn"></param>
        /// <param name="runLogInfo"></param>
        /// <returns></returns>
        public async Task WriteDBToPlcEle(WorkTaskInfo task, PlanarGeneralWriteWcsAction writeBo, PlanarGeneralPlcActionBO plcMessage, PlcConnectionS7 plcConn, RunLogInfo runLogInfo)
        {
            //写入正常报文
            writeBo.TaskCode = task.TaskCode;
            writeBo.PalletBarcode = task.PalletCode;
            writeBo.ToEquipmentCode = task.CurrentToEquipment.ToInt32();
            var writeBl = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());

            if (!writeBl)
            {
                runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机写入正常报文失败，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
            }
            else
            {
                if (writeBo.ActionType == 11)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机允许进入写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
                else if (writeBo.ActionType == 12)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机不允许进入原因：【{runLogInfo.RunLog}】;写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
                else if (writeBo.ActionType == 99)
                {
                    runLogInfo.RunLog = $"十字口{plcMessage.EquipmentCode}申请入提升机进入报错原因：【{runLogInfo.RunLog}】;写入正常报文成功，报文内容：{JsonConvert.SerializeObject(writeBo)}";
                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                }
            }
        }
    }
}
